package cn.lzh.service;

import cn.lzh.entity.Book;
import cn.lzh.mapper.BookMapper;
import cn.lzh.service.BookService;
import org.apache.ibatis.annotations.Param;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class BookServiceImpl implements BookService {
    @Autowired
    BookMapper bookMapper;
    @Override
    public List<Book> findAll() {
        return bookMapper.findAll();
    }

    @Override
    public Book findById(int id) {
        return bookMapper.findById(id);
    }

    @Override
    public void add(Book book) {
        bookMapper.add(book);
    }
    @Override
    public void update(Book b) {
        bookMapper.update(b);
    }
    @Override
    public List<Book> findPage(@Param("static") int start, @Param("num")int num, @Param("typeid")int typeid) {
        return bookMapper.findPage(start * num, num, typeid);
    }

    @Override
    public int  getCount(int typeid) {
        return bookMapper.getCount(typeid);
    }

    @Override
    public List<Book> findByName(String name, int start, int num) {
        return bookMapper.findByName(name,start,num);
    }


    @Override//分页
    public List<Book> findPageRate(int start, int num, int typeid) {
        return bookMapper.findPageRate(start * num, num, typeid);
    }

    @Override
    public List<Book> findPageSale(int start, int num, int typeid) {
        return bookMapper.findPageSale(start * num, num, typeid);
    }

    @Override
    public List<Book> findPageFav(int start, int num, int typeid) {
        return bookMapper.findPageFav(start * num, num, typeid);
    }


    /*获得点赞前 5 的商品*/
    @Override
    public List<Book> findRate5() {
        return bookMapper.findRate5();
    }

    @Override
    public List<Book> findSale5() {
        return bookMapper.findSale5();
    }

    @Override
    public List<Book> findFav5() {
        return bookMapper.findFav5();
    }


    @Override
    public int getCountByName(String str) {
        return bookMapper.getCountByName(str);
    }
}
